<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <link rel="stylesheet" href="./layui/css/layui.css">
    <script src="./layui/layui.js"></script>
    <script src="./layui/jquery.js"></script>
    <style>
        #form{
            width:800px;
            height:500px;
            position:absolute;
            top:50%;
            left:50%;
            margin-left:-400px;
            margin-top:-250px;
        }
    </style>
</head>
<body>

<div id="form">
    <h2 style="color: #008800;margin-left: 200px;" >登录</h2>
    <div class="layui-form-item">
        <label class="layui-form-label">账户名</label>
        <div class="layui-input-inline" style="width: 200px">
            <input type="text" name="userName" id="userName" required  lay-verify="required" placeholder="请输入账户名" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">辅助文字</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码框</label>
        <div class="layui-input-inline"  style="width: 200px">
            <input type="password" name="password" id="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">辅助文字</div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">

            <button id="login"    class="layui-btn layui-btn-normal" >现在登录</button>
            <button id=""           class="layui-btn layui-btn-warm" >去注册吧</button>
        </div>
    </div>
</div>
</body>
</html>
<script>

    layui.use(['layer','jquery'], function(){

        var $ = layui.jquery;
            //layer = layui.layer;

        $("#login").click(function () {
            $tempArr = isEmpty();
            $.ajax({
                url:'deal.php?model=login',
                type:'post',
                data:$tempArr,
                dataType:'json',
                async:false,
                success : function (resp) {
                    if(resp.code == 1){
                        alert(resp.msg);
                        window.location.href = "article.html";
                    }else{
                        alert(resp.msg);
                    }
                }
            })
        })
    });

    function isEmpty() {
        /*var tempArr = ['userName','password','nickName','introduce'];
        var nameArr = ['账户名','密码','昵称','简介'];*/
        $userName = $("#userName").val();
        $password = $("#password").val();
        //console.log($userName,$password,$nickName,$introduce);
        if($userName == ""){
            return alert('账户名不能为空');
        }
        if($password == ""){
            return alert('密码不能为空');
        }
        var dataObj = {
            'userName':$userName,
            'password':$password,
        };
        return dataObj;
    }


</script>